'use strict';


import Base from './base.js';
//import DBHelper from '../../business/db_helper.js';


var WXID2Info = require("../../business/wx_helper.js").WXID2Info;
var WXConfig = require("../../business/wx_helper.js").WXConfig;
import SocketHelper from '../../business/socketio_helper.js';
import Define from '../../business/define.js';


const querystring = require('querystring');
import GlobalCache from '../../business/global_cache.js';

var XMLParser = require("xml2js");
var buildXML = new XMLParser.Builder({
    rootName: 'xml',
    cdata: true,
    headless: true,
    renderOpts: {indent: ' ', pretty: 'true'}
});


var OpCode = {
    "AccountInfo": 1,       //账户信息
    "AccountFrozen": 2,     //冻结账户
    "AccountThaw": 3,       //解冻账户
    "LoginInfo": 4,         //登录信息
    "GoodsInfo": 5,         //背包信息
    "EmailInfo": 6,         //邮箱信息
    "StoreInfo": 7,         //摊位信息
    "DayDraw": 9,            //天天抽奖
    "BankInfo": 10,          //保险柜明细
    "LuckyRMBInfo": 11,      //现金红包明细
    "TakeHongBao": 12,       //领取5元现金红包
    "ModifyBankPwd": 13,    //修改保险柜密码
    "GetADLink": 14,    //获取 推广链接
};


export default class extends Base {

    async parseXML(string) {
        return await new Promise((resolve, reject) => {
            XMLParser.parseString(string, {explicitArray: false}, function (err, result) {
                resolve(result.xml);
            })
        });
    }


    getSignature(nonce, timestamp, token) {
        var strArray = [nonce, timestamp, token];
        return global.sha1(strArray.sort().join("")).toLowerCase();
    }


    async __before() {

        var param = this.param();


        var signature = param.signature;
        var timestamp = param.timestamp;
        var nonce = param.nonce;
        var echostr = param.echostr;

        if (this.getSignature(nonce, timestamp, WXConfig.token) != signature) {
            return this.http.end("签名错误");
        }


        this.postData = await new Promise((resolve, reject) => {

            var postData = "";
            this.http.req.on("data", data => {
                postData += data;
            });
            this.http.req.on("end", () => {
                resolve(postData);
            });
        });

        if (!this.postData) {
            return this.http.end(echostr);
        }

    }

    replyTextMessage(replyContent, openID) {
        var reply = {
            Content: replyContent,
            ToUserName: openID,
            FromUserName: this.wxID,
            CreateTime: Date.now(),
            MsgType: "text",
        };

        var body = buildXML.buildObject(reply);
        this.http.end(body);
    }

    //推荐专属图文链接
    replyRecommendNewsMessage(url, picUrl, qrUrl, openID) {

        var articles = {
            item: [
                {
                    Url: qrUrl,                //点击图文消息跳转链接
                    PicUrl: picUrl,             //图片链接，支持JPG、PNG格式，较好的效果为大图360*200，小图200*200
                    Title: "推荐一款超好玩的游戏，点击扫码查看游戏内容",        //图文消息描述
                    Description: GAMENAME + "是一款电玩特色的棋牌游戏，包含水浒传、古怪猴子、连环夺宝、熊之舞、德州扑克、奔驰宝马、金蟾捕鱼、深海捕鱼等多达26款热门游戏",              //图文消息标题
                }
            ]
        };

        this.replyNewsMessage(articles, openID);
    }


    //发送图文消息
    replyNewsMessage(articles, openID) {

        var reply = {

            Articles: articles,      //多条图文消息信息，默认第一个item为大图,注意，如果图文数超过8，则将会无响应
            ArticleCount: articles.item.length,
            ToUserName: openID,
            FromUserName: this.wxID,
            CreateTime: Date.now(),
            MsgType: "news",
            // Url: articles.item[0].Url,                //点击图文消息跳转链接
            // PicUrl: articles.item[0].PicUrl,             //图片链接，支持JPG、PNG格式，较好的效果为大图360*200，小图200*200
            // Description: articles.item[0].Description,        //图文消息描述
            // Title: articles.item[0].Title,              //图文消息标题
        };

        var body = buildXML.buildObject(reply);
        this.http.end(body);
    }
    //发送图片消息
    replyImageMessage(mediaId, openID) {
        var reply = {
            ToUserName: openID,
            FromUserName: this.wxID,
            CreateTime:Date.now(),
            MsgType: "image",
            Image:{MediaId: mediaId},
        };
        //console.log("+++++++++++++++"+JSON.stringify(reply));
        var body = buildXML.buildObject(reply);
        //console.log("+++++++++++++++"+body);
        this.http.end(body);
    }

    //消息接口
    async messageAction() {

        if (!this.postData) {
            return;
        }

        var obj = await this.parseXML(this.postData);
//console.log("=================="+JSON.stringify(obj));
        var saveMessage = {};

        var ignoreAttr = ["ToUserName", "FromUserName", "CreateTime", "MsgType", "MsgId"];

        for (var attr in obj) {

            if (ignoreAttr.indexOf(attr) == -1) {
                saveMessage[attr] = obj[attr];
            }
        }

        //DBHelper.saveWXMessage(obj.ToUserName, obj.FromUserName, new Date(obj.CreateTime * 1000), obj.MsgType, obj.MsgId, JSON.stringify(saveMessage));

        this.wxID = obj.ToUserName;
        switch (obj.MsgType) {
            case "event":
                this.wxHandleEvent(obj.Event, obj.EventKey, obj.FromUserName);
                break;

            case "text":
                this.wxHandleText(obj.Content, obj.FromUserName);
                break;

            case "image":
                this.replyTextMessage("您发送的图片我们已收到，如有问题需联系客服解决，请详细描述您的问题。如需自助服务，请点击【更多-帮助】", obj.FromUserName);
                break;

            case "voice":
                this.replyTextMessage("如有问题需联系客服解决，请用文字详细描述您的问题。如需自助服务，请点击【更多-帮助】", obj.FromUserName);
                break;

            case "video":
                this.replyTextMessage("您发送的视频我们已收到，如有问题需联系客服解决，请详细描述您的问题。如需自助服务，请点击【更多-帮助】", obj.FromUserName);
                break;

            case "location":
                this.replyTextMessage("您发送的位置信息我们已收到，如有问题需联系客服解决，请详细描述您的问题。如需自助服务，请点击【更多-帮助】", obj.FromUserName);
                break;

            default:
                this.replyTextMessage("暂不支持的消息类型，如有问题需联系客服解决，请详细描述您的问题。如需自助服务，请点击【更多-帮助】", obj.FromUserName);
                break;
        }
    }

    wxHandleText(text, openID) {

        //指令
        if (/^\d*#.*/.test(text)) {

            if (text.startsWith("0#")) {
                var newPassword = text.replace(/0#(.*)/, "$1");

                if (!newPassword.match(/^\S{6,20}$/) || (newPassword.match(/[^\x00-\xff]/))) {
                    this.replyTextMessage("密码长度必须在6到20, 且不包含非法字符", openID);
                    return false;
                }

                this.handleAccountMessage(OpCode.ModifyBankPwd, openID, global.sha1(newPassword.trim()));
            }
            else if (text == "1#") {
                //冻结
                this.handleAccountMessage(OpCode.AccountFrozen, openID);
            }
            else if (text == "2#") {
                //解冻
                this.handleAccountMessage(OpCode.AccountThaw, openID);
            }
            else if (text.startsWith("3#")) {
                //保险柜明细
                var page = Number(text.replace(/3#(\d*)/, "$1"));
                if (isNaN(page) || !page) {
                    page = 1;
                }
                //解冻
                this.handleAccountMessage(OpCode.BankInfo, openID, null, null, (page - 1) * 5, 5);
            }
            else if (text.startsWith("4#")) {
                //红包明细
                var page = Number(text.replace(/4#(\d*)/, "$1"));
                if (isNaN(page) || !page) {
                    page = 1;
                }
                //解冻
                this.handleAccountMessage(OpCode.LuckyRMBInfo, openID, null, null, (page - 1) * 5, 5);
            }

            else if (text.startsWith("5#")) {
                //登录明细
                var page = Number(text.replace(/5#(\d*)/, "$1"));
                if (isNaN(page) || !page) {
                    page = 1;
                }

                this.handleAccountMessage(OpCode.LoginInfo, openID, null, null, (page - 1) * 5, 5);
            }
            else if (text.startsWith("6#")) {
                //邮件明细
                var page = Number(text.replace(/6#(\d*)/, "$1"));
                if (isNaN(page) || !page) {
                    page = 1;
                }
                this.handleAccountMessage(OpCode.EmailInfo, openID, null, null, (page - 1) * 5, 5);
            }
            else {
                var replyContent = '未支持指令';
                this.replyTextMessage(replyContent, openID);
            }
        }
        else if (/^\d*$/.test(text)) {
            this.wxHandleEvent("CLICK", "Help", openID);
        }
        else if ((text.includes("实名") || text.includes("认证"))) {
            if (text.includes("不了") || text.includes("失败") || text.includes("错")) {
                var replyContent = '我们是向运营商付费请求验证您手机和真实姓名是否一致，如果您确认填写的是自己的手机和姓名，那就是您的手机号在购买的时候没有实名。请勿使用他人信息实名认证，否则可能被封号。';
                this.replyTextMessage(replyContent, openID);
            }
            else {
                var replyContent = '在游戏大厅点击左上角人物头像进入【个人中心-账户安全】界面进行绑定手机实名认证，如果您还未绑定正式账号，请先绑定正式账号。';
                this.replyTextMessage(replyContent, openID);
            }
        }
        else if (text.includes("充值")) {
            var replyContent = '可以在充值中心充值购买钻石赠送金币或者在商城购买金币礼包。购买金币礼包不参与【充值天天送】活动。';
            this.replyTextMessage(replyContent, openID);
        }
        else if (text.includes("金币") || text.includes("钻石") || text.includes("砖石")) {
            var replyContent = '充值购买钻石赠送金币，金币可用于游戏，钻石和金币可以在商城购买或在竞价摊位和其他玩家交易，钻石的更多功能敬请期待后续版本更新。';
            this.replyTextMessage(replyContent, openID);
        }
        else if ((text.includes("打赏") || text.includes("转账")) && text.includes("不")) {
            var replyContent = '因为大量玩家注册刷分，所以对VIP3以下的玩家提高了最低打赏金额。很抱歉给您的使用造成不便，具体规则可以点击大厅头像右边的VIP图标查看。';
            this.replyTextMessage(replyContent, openID);
        }
        else if (text.toUpperCase().includes("VIP")) {
            var replyContent = '只有在【充值中心】购买钻石赠送金币才会提升VIP等级，具体规则可以点击大厅头像右边的VIP图标查看。';
            this.replyTextMessage(replyContent, openID);
        }
        else if (text.includes("摊位")) {
            var replyContent = '竞价摊位是游戏中的交易系统，玩家可以在这里互通有无，竞价摊位暂不收取任何手续费。';
            this.replyTextMessage(replyContent, openID);
        }
        // else if (text.includes("红包大派送")) {
        //     var replyContent = '每天12:00 - 13:00，20:30 - 22:30在线红包大派送，只要在线就有机会领取红包。';
        //     this.replyTextMessage(replyContent, openID);
        // }
        else if (text.includes("话费") && (text.includes("没") && text.includes("到"))) {
            var replyContent = '充值话费一般十分钟内就会到账，请耐心等待，长时间没到账系统将会返还道具到您的背包。如果您多次重试依然没有到账，请联系客服人员处理。';
            this.replyTextMessage(replyContent, openID);
        }
        else if (text.includes("提现") || text.includes("体现") || text.includes("兑现") || text.includes("下分") || text.includes("退分") || text.includes("转出")) {
            var replyContent = '根据国家法律法规，游戏金币不可提现。';
            this.replyTextMessage(replyContent, openID);

            // if (text.includes("没") && text.includes("到")) {
            //     var replyContent = '推广红包转出微信或支付宝立即到账，没有到账请联系客服。';
            //     this.replyTextMessage(replyContent, openID);
            // }
            // else {
            //     var replyContent = '根据国家法律法规，游戏金币不可提现。推广红包非游戏产生，系统推广活动会赠送玩家推广红包，推广红包允许玩家在竞价摊位交易，推广红包可以在保险柜转出微信或支付宝。';
            //     this.replyTextMessage(replyContent, openID);
            // }
        }
        // else if (text.includes("现金") || text.includes("红包") || text.includes("骗") || text.includes("坑")) {
        //     var replyContent = '24小时现金红包雨，所有在线玩家均有机会获得，单个玩家不限中奖次数！系统每隔30秒自动发放，单个红包最高88元，每天累计发放88888元！从平均概率来说，如果您24小时都在线就能获得10元现金红包！金额达到10元，即可提现到支付宝或微信！root过或者越狱过的设备不参与此活动！温馨提示：充值和玩游戏能明显提高中奖概率！';
        //     this.replyTextMessage(replyContent, openID);
        // }
        else if (text.includes("下载") || text.includes("网站") || (text.includes("下") && text.includes("不"))) {
            var replyContent = '点击游戏下载按钮即可跳转至官网下载游戏。如果网站在微信不能访问，请使用浏览器直接输入网址：www.' + DOMAIN;
            this.replyTextMessage(replyContent, openID);
        }
        else if (text.includes("禁用") || text.includes("被封") || (text.includes("登") && text.includes("不"))) {
            var replyContent = '通过非法途径刷金币或红包将被永久性封号。如果您确定自己是正常玩家，请反馈您的游戏ID，待客服人员核实后您将额外获得赔偿。';
            this.replyTextMessage(replyContent, openID);
        }
        else if (text.includes("绑定")) {
            var replyContent = '在游戏大厅点击左上角人物头像进入【个人中心-账户安全】界面进行绑定，如果您还未绑定正式账号，请先绑定正式账号。';
            this.replyTextMessage(replyContent, openID);
        }
        else if (text.includes("解") && text.includes("绑")) {
            var replyContent = '在游戏大厅点击左上角人物头像进入【个人中心-账户安全】界面进行解绑。';
            this.replyTextMessage(replyContent, openID);
        }
        else if (text.includes("活动")) {
            var replyContent = '活动需要在游戏中参与。';
            this.replyTextMessage(replyContent, openID);
        }
        else if (text.includes("兑换") || text.includes("金币礼包")) {
            if (text.includes("券")) {
                var replyContent = '系统每隔半小时对当前在线玩家随机赠送一定数量的兑换券，多玩多得哦！背包中的所有物品都可以在竞价摊位和其他玩家交易。';
                this.replyTextMessage(replyContent, openID);
            }
            else {
                var replyContent = '金币礼包可在背包使用，兑换的金币将放到您的保险柜。';
                this.replyTextMessage(replyContent, openID);
            }
        }
        else if (text.toUpperCase().includes("TMD") || text.toUpperCase().includes("GUN") || text.toUpperCase().includes("MMP") || text.includes("妈的") || text.includes("艹") || text.includes("草") || text.includes("我操") || text.includes("操你") || text.includes("我日") || text.includes("日你")) {
            var replyContent = '请文明用语，尊重他人就是尊重自己。';
            this.replyTextMessage(replyContent, openID);
        }
        else if (text.length < 10) {
            if (text.includes("客服") || text.includes("帮助")) {
                var replyContent = '如有问题需联系客服解决，请详细描述您的问题。如需自助服务，请点击【更多-帮助】';
                this.replyTextMessage(replyContent, openID);
            }
            else {
                var replyContent = '您输入的内容过短，如有问题需联系客服解决，请详细描述您的问题。';
                this.replyTextMessage(replyContent, openID);
            }
        }
        else {
            var replyContent = '您的消息我们已收到，等待客服人员处理【客服时间9:00-23:00】，您可以继续描述更详细的信息。由于玩家数量较多，人工客服回复不及时敬请谅解。';
            this.replyTextMessage(replyContent, openID);
        }
    }


    wxHandleRecommend(sharerUnionID, openID) {
        this.getUserInfo(openID, () => {
            var userInfo = GlobalCache.openID2userInfos[openID];

            var unionID = userInfo.unionid;
            var nickname = userInfo.nickname;
            var sharerNickname = GlobalCache.unionID2userInfos[sharerUnionID] && GlobalCache.unionID2userInfos[sharerUnionID].nickname;
            // DBHelper.wxRecommendSubscribe(unionID, nickname, sharerUnionID, sharerNickname).then(rows => {
            //     if (!rows) {
            //         return;
            //     }
            //     var message = rows[0][0][0].message;

            //     console.log(sharerUnionID);
            //     var uu = GlobalCache.wxUnionID2AccountMap[sharerUnionID];

            //     var sharerOpenID = uu && uu.wxgzhOpenID;

            //     if (sharerOpenID) {

            //         WXID2Info[this.wxID].api.sendText(sharerOpenID, message, (err, success) => {
            //             console.log(err, success);
            //         });

            //     }

            // });

        });
    }

    //处理事件
    wxHandleEvent(eventName, eventKey, openID) {
        var replyContent = '您的消息我们已收到，等待客服人员处理，您可以继续反馈更详细的消息!如需自助服务请点【更多-帮助】';
var _that=this;
        //关注
        if (eventName == "subscribe") {

            if (eventKey) {
                var unionID;
                //如果以这个开头
                if (eventKey.startsWith("qrscene_GuanZhu_")) {
                    unionID = eventKey.substr("qrscene_GuanZhu_".length);
                }
                else if (eventKey.startsWith("GuanZhu_")) {
                    unionID = eventKey.substr("GuanZhu_".length);
                }

                //处理好
                if (unionID) {
                    this.wxHandleRecommend(unionID, openID);

                }

            }

            replyContent = `您好， 欢迎关注588棋牌游戏，游戏中遇到任何问题都可以在这里直接反馈。
            588棋牌游戏是一款电玩特色的棋牌游戏，包含水浒传、古怪猴子、连环夺宝、熊之舞、德州扑克、奔驰宝马、金蟾捕鱼、深海捕鱼等多达26款热门游戏，丰富多彩经典刺激的玩法，精致唯美的画面效果，让你欲罢不能！
如需帮助请联系在线客服为您解决`;
this.replyTextMessage(replyContent, openID);
        }
        else if (eventName == "CLICK") {
            console.log("====================");

            var type = OpCode[eventKey];

            if (type) {
                this.handleAccountMessage(type, openID);
                return;
            }
            else {
                switch (eventKey) {


                case "Feedback":
                    replyContent = "游戏中遇到任何问题都可以在这里直接反馈。";
                    this.replyTextMessage(replyContent, openID);
                    break;
                        //获取下载链接
                case "GetDownUrl":
                //console.log("获取下载链接");
                _that.replyTextMessage("http://cdn.ac09u.com/", openID);
                break;
                case "ActivityDesc":
                //console.log("获取下载链接");
                _that.replyTextMessage("请进入游戏查看最新游戏活动内容！", openID);
                break;
                //获取下载二维码
                case "GetDownERcode":
                //console.log("获取下载二维码");
                _that.replyImageMessage("w8_SybsqKUmPMHIXfz0yGMGVEps58qAVlH4Xg5M2CJM", openID);
                break;
                //获取客服二维码
                case "GetKefuERcode":
                //console.log("获取客服二维码");
                _that.replyImageMessage("w8_SybsqKUmPMHIXfz0yGMGVEps58qAVlH4Xg5M2CJM", openID);
                break;
                case "TuiguangDesc":
                //console.log("推广介绍");
                _that.replyTextMessage("玩家通过您的链接下载并通过微信注册的游戏，只要在平台内充值您就会获得相应的返利，每笔充值都会有返利，返利无上限！您的下载链接可在“游戏大厅”点击底部【活动-分享有礼】按钮进行分享！", openID);
                break;
                case "GoTuiGuang":
                this.replyTextMessage("请进入“游戏大厅”点击底部【活动-分享有礼】按钮进行分享链接", openID);
                break;
                default:
                        break;

                }
            }
        }
        //这个上那边直接跳转了
        else if (eventName == "VIEW") {

        }
        else if (eventName == "SCAN") {
            replyContent = "您已完成关注， 如需下载游戏， 请直接点击游戏下载!";
            this.replyTextMessage(replyContent, openID);
        }

        
    }

    getUserInfo(openID, callback) {


        var userInfo = GlobalCache.openID2userInfos[openID];
        if (userInfo != null) {
            callback();
            return;
        }

        //先获取账户信息
        WXID2Info[this.wxID].api.getUser({openid: openID, lang: 'zh_CN'}, (err, userInfo) => {

            if (err) {
                this.replyTextMessage(err, openID);
                return;
            }
            GlobalCache.unionID2userInfos[userInfo.unionid] = userInfo;
            GlobalCache.openID2userInfos[openID] = userInfo;
            callback();
        });
    }

    handleAccountMessage(type, openID, arg1Char, arg2Char, arg1Int, arg2Int) {


        this.getUserInfo(openID, () => {
            this.handleMessage(type, openID, arg1Char, arg2Char, arg1Int, arg2Int);
        });


    }

    handleMessage(type, openID, arg1Char, arg2Char, arg1Int, arg2Int) {
        var userInfo = GlobalCache.openID2userInfos[openID];
        //console.logconsole.log("data====="+JSON.stringify(userInfo));
        var unionID = userInfo.unionid;
        var headImgUrl = userInfo.headimgurl;

//推广二维码
WXID2Info[this.wxID].api.createTmpQRCode(`GuanZhu_${unionID}`, 2592000, (err, obj) => {
    var url = `${WXID2Info[this.wxID].website}?sharer=${querystring.escape(obj.ticket)}&headUrl=${querystring.escape(headImgUrl)}`;
    var imgurl="http://cdndown.ac09u.com/static/images/588dianwan.png";
    this.replyRecommendNewsMessage(url, imgurl, `https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=${querystring.escape(obj.ticket)}`, openID);
});
return;


        if (GlobalCache.wxUnionID2AccountMap[unionID] && !GlobalCache.wxUnionID2AccountMap[unionID].wxgzhOpenID) {
            GlobalCache.wxUnionID2AccountMap[unionID].wxgzhOpenID = openID;

            //更新数据库里的数据
            //DBHelper.updateWXGZHOpenID(unionID, openID);
        }

        var msgID = SocketHelper.sendMessage(Define.WeChatBusiness, {
            type: type,
            unionID: userInfo.unionid,
            arg1Char: arg1Char,
            arg2Char: arg2Char,
            arg1Int: arg1Int || 0,
            arg2Int: arg2Int || 5
        });

        SocketHelper.listenEvent(Define.WeChatBusiness, msgID, (data) => {

            if (data.errMsg) {
                this.replyTextMessage(data.errMsg, openID);
                return;
            }
            if (data.successMsg) {
                this.replyTextMessage(data.successMsg, openID);
                return;
            }

            switch (type) {
                //查询账户信息
                case OpCode.AccountInfo:

                    var userInfo = data.userInfo;


                    var replyContent = `您的账号信息如下：
ID:${userInfo.gameID},
账号:${userInfo.account || "未绑定正式账号"},
昵称:${userInfo.nickname},
身上金币:${userInfo.score},
保险柜金币:${userInfo.bankScore},
钻石:${userInfo.acer},
现金红包:${Number(userInfo.luckyRMB).toFixed(2)},
状态:${userInfo.enable == 0 ? "刷分被封号" : (userInfo.frozen != 0 ? "公众号冻结" : "正常")}
`;

                    this.replyTextMessage(replyContent, openID);
                    break;
                //冻结账户
                case OpCode.AccountFrozen:
                    this.replyTextMessage("你的账户冻结成功", openID);
                    break;
                //解冻成功
                case OpCode.AccountThaw:
                    this.replyTextMessage("你的账户解冻成功", openID);
                    break;
                //最近登录信息
                case OpCode.LoginInfo:
                    var loginInfo = data.loginInfo;

                    var replyContent = `登录信息如下:\n-----------------------`;
                    if (!loginInfo || loginInfo.length <= 0) {
                        replyContent += "\n无登录信息";
                    }
                    else {
                        for (var i = 0; i < loginInfo.length; ++i) {
                            replyContent += `
登录IP:${loginInfo[i].loginIP},
登录地址:${loginInfo[i].loginAddr},
登录时间:${new Date(loginInfo[i].loginTs).toLocaleString()},
退出时间:${loginInfo[i].logoutTs != "0000-00-00 00:00:00" ? new Date(loginInfo[i].logoutTs).toLocaleString() : "当前在线"},
登录系统:${loginInfo[i].os}
-----------------------`;
                        }

                    }

                    this.replyTextMessage(replyContent, openID);
                    break;
                //背包信息
                case OpCode.GoodsInfo:
                    var goodsInfo = data.goodsInfo;
                    var goodsDesc = "无道具";
                    if (goodsInfo && goodsInfo.length > 0) {
                        goodsDesc = "";

                        for (var i = 0; i < goodsInfo.length; ++i) {
                            goodsDesc += `道具:【${goodsInfo[i].name}】 数量:【${goodsInfo[i].count}】\n`;
                        }
                    }

                    var replyContent = `背包信息如下：
${goodsDesc}
`;
                    this.replyTextMessage(replyContent, openID);
                    break;
                //邮件信息
                case OpCode.EmailInfo:

                    var emailInfo = data.emailInfo;
                    var emailInfoDesc = "无邮件消息";
                    if (emailInfo && emailInfo.length > 0) {
                        emailInfoDesc = "";

                        for (var i = 0; i < emailInfo.length; ++i) {
                            emailInfoDesc += `邮件${i + 1}:\n内容:【${emailInfo[i].title}】 \n时间:【${new Date(emailInfo[i].createTime).toLocaleString()}】\n------------------\n`;
                        }
                    }

                    var replyContent = `邮件信息如下：
${emailInfoDesc}
`;
                    this.replyTextMessage(replyContent, openID);
                    break;


                //摊位信息
                case OpCode.StoreInfo:
                    var storeInfo = data.storeInfo;
                    var storeInfoDesc = "无摊位消息";
                    if (storeInfo && storeInfo.length > 0) {
                        storeInfoDesc = "";

                        var payTypeDesc = {0: "金币", 1: "钻石", 10: "推广红包"};

                        for (var i = 0; i < storeInfo.length; ++i) {
                            storeInfoDesc += `道具【${storeInfo[i].name}】售价【${storeInfo[i].price}${payTypeDesc[storeInfo[i].payType]}】数量【${storeInfo[i].count}】\n\n`;
                        }
                    }

                    var replyContent = `摊位信息如下：
${storeInfoDesc}
`;
                    this.replyTextMessage(replyContent, openID);

                    break;
                //活动介绍
                case OpCode.ActivityDesc:
                    var activityInfo = data.activityInfo;
                    var activityInfoDesc = "无活动消息";
                    if (activityInfo && activityInfo.length > 0) {
                        activityInfoDesc = "";


                        for (var i = 0; i < activityInfo.length; ++i) {
                            activityInfoDesc += `活动${i + 1}:【${activityInfo[i].title}】\n`;
                        }
                    }

                    var replyContent = `当前进行中的活动如下：
${activityInfoDesc}
活动需要在游戏中参与。如需下载游戏， 请直接点击游戏下载!
`;
                    this.replyTextMessage(replyContent, openID);

                    break;
                //保险柜明细
                case OpCode.BankInfo:
                    var bankInfo = data.bankInfo;
                    var bankInfoDesc = "无保险柜明细信息";
                    if (bankInfo && bankInfo.length > 0) {
                        bankInfoDesc = "";


                        for (var i = 0; i < bankInfo.length; ++i) {
                            bankInfoDesc += `【${new Date(bankInfo[i].ts).toLocaleString()}】【${bankInfo[i].type}】【${bankInfo[i].desc}】变动金额【${bankInfo[i].money}】,剩余金币:【${bankInfo[i].nowBankMoney}】\n\n`;
                        }
                    }

                    var replyContent = `保险柜明细如下：
${bankInfoDesc}
`;
                    this.replyTextMessage(replyContent, openID);

                    break;
                //现金红包明细
                case OpCode.LuckyRMBInfo:
                    var luckyRMBInfo = data.luckyRMBInfo;
                    var luckyRMBInfoDesc = "无现金红包明细信息";
                    if (luckyRMBInfo && luckyRMBInfo.length > 0) {
                        luckyRMBInfoDesc = "";


                        for (var i = 0; i < luckyRMBInfo.length; ++i) {
                            luckyRMBInfoDesc += `【${new Date(luckyRMBInfo[i].ts).toLocaleString()}】【${luckyRMBInfo[i].type}】【${luckyRMBInfo[i].desc}】变动金额【${luckyRMBInfo[i].money}】,剩余红包:【${luckyRMBInfo[i].afterMoney}】\n\n`;
                        }
                    }

                    var replyContent = `现金红包明细如下：
${luckyRMBInfoDesc}
`;
                    this.replyTextMessage(replyContent, openID);

                    break;
                case OpCode.GetADLink:
                //console.log("============="+unionID);
                    WXID2Info[this.wxID].api.createTmpQRCode(`GuanZhu_${unionID}`, 2592000, (err, obj) => {
                        var url = `${WXID2Info[this.wxID].website}?sharer=${querystring.escape(obj.ticket)}&headUrl=${querystring.escape(headImgUrl)}`;
                        var openurl="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=${querystring.escape(obj.ticket)}";
                        var imgurl="http://cdndown.ac09u.com/static/images/588dianwan.png";
                        this.replyRecommendNewsMessage(url, imgurl, openurl, openID);
                    });
                    break;

                //每日抽奖
                case OpCode.DayDraw:
                //领取5元现金红包
                case OpCode.TakeHongBao:
                //修改保险柜密码
                case OpCode.ModifyBankPwd:
                    //只发successMsg前面已经处理过了
                    break;
            }
        });
    }
}